/*
 * Module 02
 *
 */

package ua.gl.basecamp.tabachnyy.testcase;

import ua.gl.basecamp.tabachnyy.util.UserAnswersParser;

import java.util.List;

/**
 * @author yaroslav.tabachnyy@gmail.com
 * @version 1.02
 * @date 14.02.2013
 *
 */
public class TypedAnswerQuestion extends Question {
    public TypedAnswerQuestion(String stringRepresentation, List<Answer> answers) {
        super(stringRepresentation, answers);
    }

    @Override
    public double getAnswersScore(List<UserAnswer> userAnswers) {
        int correctAnswers = 0;
        for (Answer answer : getAnswers()) {
            if (answer.isCorrect() && userAnswers.contains(answer)) {
                correctAnswers++;
            }
        }
        int wrongAnswers = userAnswers.size() - correctAnswers;

        return (correctAnswers - wrongAnswers);
    }

    @Override
    public List<UserAnswer> getAnswersFromString(String userAnswersString) {
        UserAnswersParser parser = new UserAnswersParser(userAnswersString);
        return parser.getAnswersByStrings();
    }

    @Override
    public String toString() {
        return getStringRepresentation() + "(enterable question)\n";
    }
}
